-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #6497: Support global flags passed in after subcommands #8670
Conversation
Codecov ReportAll modified lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #8670 +/- ##
==========================================
- Coverage 86.61% 82.74% -3.87%
==========================================
Files 176 176
Lines 25678 25692 +14
==========================================
- Hits 22240 21260 -980
- Misses 3438 4432 +994
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mea culpa - I had missed adding the 1.5 + 1.6 backport labels to #6497. Ideally we could offer the same consistency for all our CLIs starting with v1.5+. Given how "clean" this change looks, how would you feel about backporting the change (at least the approach if not the exact commit diff) to 1.5.latest
+ 1.6.latest
?
@@ -118,6 +119,44 @@ def invoke(self, args: List[str], **kwargs) -> dbtRunnerResult: | |||
) | |||
|
|||
|
|||
# approach from https://github.com/pallets/click/issues/108#issuecomment-280489786 | |||
def global_flags(func): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is neat!
@jtcohen6 These flags need to be set at the global level, and there doesn't seem to be an easy way to globalize them everywhere: @p.warn_error
@p.warn_error_options
@p.log_format Do you want me to continue working on this, or should I merge this PR as-is and create a backlog ticket to handle these edge cases? |
I'm fine with back porting the PR in its current state to 1.5 and 1.6, but if the acceptance criteria include back porting the three errant flags highlighted above, I might need to rethink. |
@aranke That's odd - it's only those three flags which are being difficult? Do you have any sense of why? |
I'm not certain, honestly, but could be that they are being passed down incorrectly. |
I've tried many combinations, and it looks like the order in which the parameter decorators are passed in matters. Creating a backlog ticket (#8715) to investigate further, but I don't think we need to hold up this PR to globalize the three remaining flags. |
@aranke Thanks for investigating & opening the ticket! We should try to get that tech debt ticket resolved — it's important for our ability to present consistent documentation & CLI behavior (dbt-labs/docs.getdbt.com#4041) — but I agree that it shouldn't block merging the brunt of the work in this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Opened a new issue in dbt-labs/docs.getdbt.com: dbt-labs/docs.getdbt.com#4129 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@@ -167,10 +178,10 @@ def cli(ctx, **kwargs): | |||
# dbt build | |||
@cli.command("build") | |||
@click.pass_context | |||
@global_flags |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice change! What happens when a flag in global flags got passed in twice at different level with different value, which one wins?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We throw an error, similar to existing behavior.
Product guidance from jerco: #6497 (comment)
Test:
dbt-core/tests/unit/test_cli_flags.py
Lines 352 to 357 in 913b1cd
def test_duplicate_flags_raises_error(self): | |
parent_context = self.make_dbt_context("parent", ["--version-check"]) | |
context = self.make_dbt_context("child", ["--version-check"], parent_context) | |
with pytest.raises(DbtUsageException): | |
Flags(context) |
The backport to
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-1.5.latest 1.5.latest
# Navigate to the new working tree
cd .worktrees/backport-1.5.latest
# Create a new branch
git switch --create backport-8670-to-1.5.latest
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 f17c1f3fe730947f554b55e4e5471bb9cb45fd95
# Push it to GitHub
git push --set-upstream origin backport-8670-to-1.5.latest
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-1.5.latest Then, create a pull request where the |
resolves #6497
Problem
Solution
Checklist